﻿Chenxin.UI.PgPaidItems = Chenxin.extend(Chenxin.UI.PageCommon, {
    actionUrl: "/service/logic/PaidItems.ashx",
    createSearch: function() {
        return new Chenxin.UI.SrhPaidItems({
            scope: this
        });
    },
	
    createGrid: function() {
		_this = this;
        return new Chenxin.UI.ReportGrid({
            actionUrl: this.actionUrl + '?op=search',
            pageSize:100,
            hasTotal:false,
            hasPage:true,
            cellBorder: true,
            height:400,
            autoLoad: false,
            renderTo: 'divShowPaidItems',
            hasCheckBox: false,
            id: 'PaidItems',
            title: '我的实收',
			createTitleTool:function(){					
				return [{
					text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
					scope:this,
					title:'导出全部数据',
					handler:function(el){
						_this.exportAll();
					}
				}];
			},
            scope: this,
            columns: {
                AreaName: {
                    width: 120,
                    head: '商圈',
                    sortable: true,
					captionCol:true
                },
                PointDepart: {
                    width: 120,
                    head: '部门',
                    sortable: true,
					inTotal: false
                },
                ContractCode: {
                    width: 120,
                    head: '成交编号',
                    sortable: true,
					inTotal: false
                },
                ContractDate: {
                    width: 80,
                    head: '成交日期',
                    sortable: true,
					inTotal: false
                },
                HouseAddress: {
                    width: 355,
                    head: '房源地址',
                    sortable: true,
					inTotal: false
                },
                PointEmp: {
                    width: 100,
                    head: '业务员',
                    sortable: true,
					inTotal: false
                },
                DeparterManagerName: {
                    width: 100,
                    head: '店长',
                    sortable: true,
					inTotal: false
                },
                MangerName: {
                    width: 100,
                    head: '高级经理',
                    sortable: true,
					inTotal: false
                },
                RegionManagerName: {
                    width: 100,
                    head: '区域经理',
                    sortable: true,
					inTotal: false
                },
                MajordomoName: {
                    width: 100,
                    head: '总监',
                    sortable: true,
					inTotal: false
                },
                StanCommision: {
                    width: 100,
                    head: '标准佣收',
                    sortable: true,
					inTotal: false
                },
                RealCommisionFinal: {
                    width: 100,
                    head: '应收佣收',
                    sortable: true,
					inTotal: false
                },
                CommisionFinal: {
                    width: 100,
                    head: '折佣',
                    sortable: true,
					inTotal: false
                },
                ConsultingFinal: {
                    width: 100,
                    head: '咨询费',
                    sortable: true,
					inTotal: false
                },
                Point: {
                    width: 100,
                    head: '点数',
                    sortable: true
                },
                PayMoney: {
                    width: 100,
                    head: '实收',
                    sortable: true,
					inTotal: false
                },
                ApportionRealCommisionFinal: {
                    width: 100,
                    head: '分配应收佣收',
                    sortable: true,
                },
                ApportionCommisionFinal: {
                    width: 100,
                    head: '分配折佣',
                    
                    sortable: true
                },
                ApportionConsultingFinal: {
                    width: 100,
                    head: '分配咨询费',
                    sortable: true
                },
                ApportionPay: {
                    width: 100,
                    head: '分配实收',
                    sortable: true
                },
                PayDate: {
                    width: 100,
                    head: '收款日期',
                    sortable: true,
					inTotal: false
                },
                PayArchDate: {
                    width: 100,
                    head: '实收归属日期',
                    sortable: true,
					inTotal: false,
					renderer: function(val, field, row) {
                        if (val.indexOf('.') >= 0) {
                            return val.substring(0, 4) + '年' + val.substring(5.1) + '月';
                        }
                        else {
                            return '';
                        }
                    }
                },
                ContractArchDate: {
                    width: 100,
                    head: '业绩归属日期',
                    sortable: true,
					inTotal: false
                },
                ContractCompanyName: {
                    width: 100,
                    head: '合同归属公司',
                    sortable: true,
					inTotal: false
                }
            }
        });
    },
	exportAll:function(){
		_this = this;
        paramStr = this.search.getParamJson();
        paramStr.op = 'exportAll';
        Chenxin.Msg.Waiting.show();
		Chenxin.Fn.exportToExcelByServer(this.actionUrl,paramStr,'导出文件');
		//$.ajax({ url: this.actionUrl, data: paramStr,async:false});
		Chenxin.Msg.Waiting.hide();
	}
});

/*
*检索面板
*/
Chenxin.UI.SrhPaidItems = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    initEvent: function() {
        var objSrh = this;
        /**********事件：检索********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });

        /********事件：实收归属日期******/
        $("#txtArcTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        var curdate = new Date();
        $('#txtArcTime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));

        /********事件：开始时间******/
        $("#txtStartTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });

        /********事件：结束时间******/
        $("#txtEndTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });

        $('#txtKeyword').defText({
            deftxt: '成交编号/房源地址'
        });

        $("#txtStartTime").defText({
            deftxt: '开始时间'
        });

        $("#txtEndTime").defText({
            deftxt: '结束时间'
        });
    },
    createComboList: function() {
        //日期类型
        var cmbDateType = new Chenxin.UI.Combo({
            containerId: '#DateType',
            tbxWidth: 75,
            addPleaseSelected: false,
            items: comboCommon.PaidItemsDateType
        });

        //合同城市
        var cmbContractCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#ContractCityId',
            name: 'ContractCityId',
            tbxWidth: 45,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    cmbContractCompanyId.clearItems();
                } else {
                    cmbContractCompanyId.param.fatherid = this.getValue();
                    cmbContractCompanyId.reload();
                }
            }
        });
        //合同公司
        var cmbContractCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#ContractCompanyId',
            name: 'ContractCompanyId',
            tbxWidth: 45
        });
        
        //类型
        var cmbType = new Chenxin.UI.Combo({
            containerId: '#divtype',
            name: 'type',
            items: [{ txt: '全部', val: '0' }, { txt: '买卖', val: '10' }, { txt: '租赁', val: '20' }, { txt: '零散', val: '30' }, { txt: '其他', val: '40' }],
            tbxWidth: 45
        });

        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(cmbDateType);
        structs.push(cmbContractCityId);
        structs.push(cmbContractCompanyId);
        structs.push(cmbType);
        return structs;
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.PgPaidItems();
});